<?php

class ArctinyModel extends CommonModel {
    //主表自动验证
    protected $_validate=array(
        array('title','require','标题不能为空',1),
        array('typeid','require','请选择分类',1),
        array('typeid','number','分类id不合法',1)
    );
    //自动完成
    protected $_auto=array(
        array("status","1"),
        array("senddate","time","1","function"),
        array("update","time","3","function"),
        array("flag","_autoFlag",3,"callback")
    );
    //flag字段自动完成处理
    protected function _autoFlag($data){
        if(isset($data) && is_array($data)){
            return implode(",",$data);
        }
        return "";
    }
    //文档总数
    function totalcount($condition=""){
        $count=$this->field('id')->where($condition)->count();
        if(!$count){
            $count=0;
        }
        return $count;
    }
    
    //分页文档列表
    function getPageArclist($condition="",$left=0,$rows=0){
        $list=$this->alias('a')->field("a.*,t.name as typename,c.name as channelname")->join(" __ARCTYPE__ as t on t.id=a.typeid")->join("__CHANNEL__ as c on c.id=a.channelid")->where($where)->order("a.id asc")->limit("{$left},{$rows}")->select();
        return $list;
    }
}
